package com.wanqing.listenerMQ;

import com.wanqing.dto.AsynSubmitOrderDTO;
import com.wanqing.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class AsynProcessingListener {
    private final OrderService orderService;

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "wanqing.submit.order.success.queue", durable = "true"),
                    exchange = @Exchange(name = "submit.order.topic"),
                    key = "submit.order.success"
            )
    })
    public void listenSubmitOrderSuccess(AsynSubmitOrderDTO asynSubmitOrderDTO){
        log.info("异步处理订单成功：{}", asynSubmitOrderDTO);
        orderService.asynSubmitOrderSuccess(asynSubmitOrderDTO);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "wanqing.pay.success.queue", durable = "true"),
                    exchange = @Exchange(name = "pay.topic"),
                    key = "pay.success"
            )
    })
    public void listenPaySuccess(String outTradeNo){
        log.info("异步处理支付成功：{}", outTradeNo);
        orderService.paySuccess(outTradeNo);
    }
}
